<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数案例2</title>
    <script>
        // 1.利用函数求数组的翻转
        // var arr = [1, 2, 3, 4, 5];
        var arr2 = ['blue', 'pink', 'red', 'black'];

        function getfan(arr1) {
            // if (arr1 instanceof Array) {
            if (Array.isArray(arr1)) {
                var newarr = [];
                for (var i = arr1.length - 1; i >= 0; i--) {
                    newarr[newarr.length] = arr1[i];
                }
                return newarr;
            } else {
                console.log('输入的不是数组，请重新输入');
            }
        }
        console.log(getfan(1, 2, 3));
        console.log(getfan(arr2));

        // 2.利用函数对数组排序
        /*  function sort(arr) {
             for (var i = 0; i < arr.length; i++) {
                 for (var j = 0; j < arr.length - i - 1; j++) {
                     var temp;
                     if (arr[j] < arr[j + 1]) {
                         temp = arr[j];
                         arr[j] = arr[j + 1];
                         arr[j + 1] = temp;
                     }
                 }
             }
             return arr;
         }
         var arr1 = [2, 4, 3, 21, 34, 32, 77];
         console.log(sort(arr1)); */

        // 3.利用函数判断闰年
        /*  function isrunyear(year) {
            var a;
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                a = '闰年';
            } else {
                a = '平年';
            }
            return a;
        } 
        var year = 2001
        console.log(isrunyear(year));  */

        // 4.用户输入年份，告诉他当前年份的二月份天数
        /* var year1 = prompt('请输入一个年份');
        alert(month());

        function year(year2) {
            var a = 0
            if ((year2 % 4 == 0 && year2 % 100 != 0) || year2 % 400 == 0) {
                a = 1;
            } else {
                a = 0;
            }
            return a;
        }

        function month() {
            var days = 0;
            if (year(year1) == 1) {
                days = 29;
            } else {
                days = 28;
            }
            return days;
        } */
    </script>
</head>

<body>

</body>

</html>